package com.wyh.blog.controller;

import com.wyh.blog.model.vo.request.UserLoginRequest;
import com.wyh.blog.model.vo.response.UserInfoVo;
import com.wyh.blog.model.vo.response.UserVo;
import com.wyh.blog.service.intf.UserService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Slf4j
public class UserInfoController {
    @Resource(name = "userServiceImpl")
    UserService userService;

    @RequestMapping("/login")
    public UserInfoVo login(@RequestBody @Validated UserLoginRequest userLoginRequest){
        log.info("用户登录，userName:{}", userLoginRequest.getUserName());
        return userService.login(userLoginRequest.getUserName(),
                userLoginRequest.getPassword());
    }

    @RequestMapping("/getUserInfo")
    public UserVo getUserInfo(@NotNull(message = "用户id不能为空") Integer id){
        log.info("获取用户信息，id:{}", id);
        UserVo userInfo = userService.getUserInfo(id);
        return userInfo;
    }

    @RequestMapping("/getAuthorInfo")
    public UserVo getAuthorInfo(@NotNull(message = "博客id不能为空") Integer id){
        log.info("获取用户信息，id:{}", id);
        UserVo userVo = userService.getAuthorInfo(id);
        return userVo;
    }
}
